/*
 * Copyright (c) 2021 Zsj. All rights reserved.
 */

package com.jzz.crawlerweb.controller;

import com.jzz.crawlerweb.handler.generator.TextCaptchaGenerator;
import com.jzz.crawlerweb.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 该接口仅用作测试
 */
@RequestMapping("/test")
@Controller
public class TestController {

    @Autowired
    private TestService testService;

    @ResponseBody
    @RequestMapping("/hi")
    public String hi() {
        return testService.hi();
    }

    @ResponseBody
    @GetMapping(value = "/code/{text}", produces = MediaType.IMAGE_JPEG_VALUE)
    public byte[] code(@PathVariable String text) {
        return new TextCaptchaGenerator(text).renderBytes();
    }
}
